let _project = ref [] (* filelist *)
let name = "my_new_project"

let list_dir_files dir =
  let fileList = Sys.readdir dir in
  let _ = Array.sort (String.compare) fileList in
  Array.iter
    (fun file ->
      let path = Filename.concat dir file in
      if not (Sys.is_directory path) then
        print_endline path)
    (fileList)
    
let project_create_ocaml name =
  _project := "main.ml" :: [];
  let make_files () = 
    let cmd = "cp "^"./templates/main.ml ./"^name^"/main.ml" in  
    let _ = Sys.command cmd in
    print_endline cmd;
    let mFile = open_in "./templates/Makefile" in
    let maFile = open_out ("./"^name^"/Makefile") in
    output_string maFile ("# Makefile Generique\n\nPRG = "^name^"\n");
    try
      while (true) do
        let line = input_line mFile in
        output_string maFile (line^"\n")
      done
    with End_of_file -> close_in mFile;
    close_out maFile;
    _project := "Makefile" :: (name^".proj") :: !_project
  in
  try Unix.mkdir name 0o775; make_files () with Unix.Unix_error (e,_,_) -> make_files ()

let project_write name files = 
  let pFile = open_out ("./"^name^"/"^name^".proj") in
  List.iter (fun x -> output_string pFile (x^"\n")) files;
  close_out pFile

let _ = 
  list_dir_files "."
  
  (*  
  project_create_ocaml name;
  project_write name !_project
  *)
